home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 8_16BIT / PPFAQ.ZIP / PIC84FAQ.TXT next >
Encoding:
Text File  |  1995-03-16  |  32.0 KB  |  658 lines

  1.  
  2.       Frequently Asked Questions About PIC84PGM.ZIP With Some Answers 
  3.       ===============================================================
  4.       (Original 11th March 95)                    V-0.1 16th March 95
  5.  
  6.                               David Tait
  7.  
  8.                       Electrical Engineering Dept
  9.                             The University
  10.                            Manchester M13 9PL
  11.                                   UK
  12.  
  13.                          david.tait@man.ac.uk
  14.             
  15.  
  16.                      Copyright (C) 1995 David Tait
  17.    Permission is granted to copy, store or redistribute this document.
  18.  
  19.  
  20. Introduction
  21. ------------
  22.  
  23. PIC84PGM.ZIP (available from ftp.ee.ualberta.ca/pub/cookbook/comp/ibm,
  24. Microchip's BBS in the 3RDPARTY library, and elsewhere) contains a
  25. crude ASCII schematic for a simple PIC16C84 programmer designed to be
  26. attached to the parallel port of a PC. It also includes the source
  27. code for some rudimentary C and QBasic drivers for the hardware.  In
  28. case you don't know, the PIC16C84 is a single chip microcontroller
  29. which fits a lot of good things into a small (18-pin) package; in fact
  30. it is a developers dream come true.  It's fast, moderately cheap, and
  31. best of all it's program is stored in EEPROM.  This last feature makes
  32. it especially convenient in the development stages of a project; it
  33. even has cheaper one-time programmable (OTP) cousins for use in a
  34. final product.  Another useful attribute of the 16C84 is that it can
  35. be programmed with only a few signals (called serial mode programming)
  36. and what's more, the required signals have very lax timing specs.  As
  37. a considerable bonus, the manufacturer, Microchip Technology Inc,
  38. provide free PIC development software via their BBS or Internet site.
  39. You can also grab useful software and information from the Internet
  40. site of Parallax Inc, a company that supports the PIC series.  It is
  41. true that both these companies also sell some reasonably priced
  42. prototype programmers, but if you want a dedicated 16C84 programmer,
  43. the DIY route is quite attractive.
  44.  
  45. When I looked about a year ago I couldn't find anything to help me
  46. build a programmer so I just got the required info from Microchip and
  47. did it myself; it was not very difficult (I had to have a couple of
  48. goes at getting the hardware right though).  I decided to make my info
  49. available on the net just in case it helped anyone about to re-invent
  50. this particular "wheel".  It turns out I didn't explain things as
  51. comprehensively as I should have done and the legacy of this project
  52. has been a steady stream of e-mail that has to be answered.  It seems
  53. that many people from all over the world are just discovering the
  54. delights of the 16C84 and would like a cheap and cheerful development
  55. system to go with it.  Helped no doubt by the very useful PIC FAQ
  56. produced by Tom Kellett et al, these same people get to hear about my
  57. humble efforts.  I guess most people that grab the files just take the
  58. good bits (if indeed there are any) and get on with designing their
  59. own superior versions.  It's likely I'll never hear from this group at
  60. all.  I suspect this group own oscilloscopes.  On the the other hand
  61. there are some people that assume that my design can replicated
  62. exactly and will work from the first moment they apply power, and
  63. though this will be true for a lucky few, on the whole this group run
  64. into some kind of hardware/software problems.  Needless to say this
  65. group are unlikely to own oscilloscopes and I certainly do hear from
  66. them.  I try hard to help, but faultfinding by e-mail is a frustrating
  67. experience at best.  I feel responsible for their disappointment and
  68. frustration.  All is not lost though; there are some common stumbling
  69. blocks that account for most of the problems that can crop up.  The
  70. purpose of these notes is just to describe the potential gremlins and
  71. their cures, and to answer one or two other questions that I'm often
  72. asked.  I'm sorry this file is so long and rambling, but I hope that
  73. if I answer everything now as fully as possible, I might get a rest
  74. from answering the same questions multiple times by e-mail.
  75.  
  76. Some answers refer to my programs for reading a PIC.  The software is
  77. supplied as both C (rp.c) and QBasic (rp.bas) source and should be
  78. available where you picked up this document or even packaged with it.
  79. The software is only designed to read program memory but it's really
  80. very easy to modify it to read other areas of the 16C84 memory.  See
  81. the source comments for details on how to run the programs.
  82.  
  83.  
  84.  
  85. Hardware Questions
  86. ------------------
  87.  
  88. Q1. Has _anybody_ got this to work?
  89.  
  90. A1. Yes.  At least 40-50 people have been kind enough to send me mail
  91. to say they got it working themselves.  I've lost count of the number
  92. people I have tried to help by e-mail.  I suspect that a great many
  93. others have got it to work too, but they have not got in touch for one
  94. reason or another.  Ask any shareware writer about the likely ratio of
  95. registered users to total users and then remember my stuff is free, so
  96. there is not much incentive to get in touch. (Unless there is a
  97. problem that is, which is the motivation behind this document in the
  98. first place.)  As I write this, I see that the file has been
  99. downloaded well over a thousand times from the Microchip BBS alone.
  100.  
  101.  
  102. Q2. Your drawing shows devices marked 74xx07 and 74xx06.  I can't find
  103. them in any catalogue, where can I get them?
  104.  
  105. A2. I just meant any TTL open-collector (O/C) buffer like the plain
  106. 7407 or 7406, or better still if you can get them, the 74LS07 or the
  107. 74LS06.  Similar members of the 74HC family are probably OK if such
  108. things exist.  One of my programmers uses a 74LS05 which is really out
  109. of spec in this circuit, but seems to work fine.  I didn't think the
  110. choice of buffer was critical, but a few reports have made me think
  111. again about using the plain 7406 or 7407.  I understand that another
  112. popular 16C84 programmer design uses a 74C906, and this slightly more
  113. modern device may have been a better choice for my programmer too.  If
  114. you want to try one, please note that it is not a drop-in replacement
  115. for a 7406.  It seems you can be even more adventurous about replacing
  116. the buffer: one person told me that he couldn't find a suitable chip
  117. in his junkbox so he replaced the buffers with 5 VMOS FETs and they
  118. worked a treat.  I suppose it is even possible to connect the PIC
  119. directly to the parallel port and do away with the buffers altogether.
  120. Though this needs a little trickiness because RB7 is read/write.
  121. Anyway, I wouldn't recommend this, but I know it can be done.  For the
  122. real minimalist, do this and replace the electronic switches with
  123. manual ones and get the program to prompt you to operate them at the
  124. correct times!
  125.  
  126.  
  127. Q3. Your diagram implies that either inverting or non-inverting buffers
  128. can be used.  Surely they can't be interchangeable, or can they?
  129.  
  130. A3. Well not exactly.  This is something I should have mentioned in
  131. the README but didn't.  You _can_ use either type of buffer but you
  132. must make sure the software is changed accordingly.  As supplied, the
  133. source and the EXE file assume inverting buffers are used (i.e. the
  134. 74xx06 type).  In fact as one of the 6 available buffers is not used I
  135. actually missed an opportunity to make the hardware self configuring.
  136. If I had connected the input of the spare buffer to an output pin of
  137. the parallel port and the output of the buffer to an input pin the
  138. software could have worked out itself whether the buffer inverted or
  139. not.  Oh well.  You should refer to the software section if you
  140. happened to select non-inverting buffers to build the circuit.
  141.  
  142.  
  143. Q4.  It would make my life easier if you could supply me with a PCB
  144. layout.  Do you have one?  What about a better diagram at least?
  145.  
  146. A4.  Recently one satisfied user promised to send me a layout so that
  147. I could make it generally available.  I don't have it yet, but when I
  148. do I'll ask the designer whether I can upload it to the circuit
  149. cookbook site.  Actually it's not obvious that a PCB layout of the
  150. circuit exactly as shown would be the most useful.  I mentioned in the
  151. README file that the spare sections of the 4066 could be used to
  152. isolate the RB6 and RB7 pins from the buffers.  Maybe it wasn't
  153. obvious, but I meant that this would be a good way to implement an
  154. in-system programming system.  You'll also need to arrange for MCLR to
  155. be taken to +5V for the PIC to run - a diode to +5V is probably OK; in
  156. fact someone sent me a diagram of exactly this setup so they obviously
  157. got the message.  If you want to design your own PCB it shouldn't be
  158. too much of a problem; the low complexity of this programmer is
  159. ideally suited for use in evaluating the numerous demo versions of PCB
  160. software that are in circulation.  I was quite impressed with a demo
  161. of CIRCAD (no, not the program by the same name that's on the Simtel
  162. sites).  As I write this, a copy can be snatched from
  163. ftp://mobius.gmu.edu/pub/circad.  It has both PCB layout functions and
  164. schematic capture so you can draw a better diagram yourself!  Recently
  165. Don Mckenzie has posted info on the 3RDPARTY file area of the
  166. Microchip BBS about a supply of PCBs for his own programmer design.
  167. He doesn't have Internet access but you can reach him on the Microchip
  168. BBS e-mail system where his user ID is simply don mckenzie.  I only
  169. mention this here because he supplies his own improved version of my
  170. QBasic software and he was kind enough to send me a free PCB :-) See
  171. the PIC FAQ about connecting to the BBS if you want to get in touch
  172. with him.
  173.  
  174.  
  175. Q5. I have built your hardware exactly as shown and it doesn't work!
  176. I have checked it a hundred times and it looks OK to me.  Are you
  177. _sure_ the diagram is correct?
  178.  
  179. A5. Well, the fact that it doesn't work might not be due to the
  180. programmer hardware alone and you should look at the answers to the
  181. software questions too.  To answer the correctness question: the
  182. diagram is correct as far as it goes.  My first programmer of this
  183. type was more or less exactly as shown.  However it does suffer from
  184. some sins of omission.  I should have made it clear that it is
  185. necessary to add decoupling capacitors for the 4066 and the buffer.
  186. The decoupling components are not shown in the diagram, but 100nF caps
  187. should be connected between, and close to, the power pins of both
  188. chips.  As one of my e-mail correspondents put it: if the person
  189. building this circuit didn't know that they should add decoupling
  190. caps, then they are going to have a terrible time getting their PIC
  191. applications to work.  That made me feel good for a minute or so, then
  192. I felt guilty again because I hadn't made the need for decoupling
  193. explicit.  The circuit is deceptively simple, but it is not that easy
  194. for an absolute beginner to go from my diagram to a working
  195. programmer.  Not really a correction, but a couple of LEDs on VPP and
  196. VDD, while not helping the circuit work any better, are at least
  197. colourful and let you know that things are working.  By the way,
  198. rather than just giving the board a visual check, I would urge you to
  199. write a simple program to toggle the LPT output pins (D0-D3) and read
  200. the input pin (-ACK) - QBasic is great for this.  If you don't have
  201. any test equipment, use the spare buffer to drive an LED and use this
  202. as a simple logic probe.  Getting the pins to change as expected will
  203. go 99% of the way to solving your problems.
  204.  
  205.  
  206. Q6.  Why 13.8V?
  207.  
  208. A6.  Initially I used a power supply intended for citizen's band or
  209. amateur radio equipment (I have such a thing handy because I'm a radio
  210. ham - G0JVY).  As much of this equipment is expected to be used
  211. mobile, i.e. in a car or truck, the power supply is designed to
  212. produce the typical voltage of a fully charged car battery - 13.8V
  213. apparently.  You don't have to follow this slavishly; the spec is
  214. something like VDD+4V (i.e. 9V) to 14V, but I'm reliably informed that
  215. using too low a voltage can lead to unreliable programming.  A 3-pin
  216. 12V regulator, like a 7812, with a couple of silicon diodes from its
  217. ground lead to ground gives a decent enough 13.2V when supplied with
  218. 16-18V from a unregulated wall adapter.  Following a suggestion made
  219. on the net, I mentioned in the README that it's possible to get power
  220. from a spare floppy disk lead.  After hearing a sad tale from someone
  221. who tried this, I no longer think that's a good idea.
  222.  
  223.  
  224. Q7.  Anything I should know about the cable between the PC and the
  225. programmer?
  226.  
  227. A7.  Keep it short for one thing. There are some fast pulses
  228. travelling along this connection and long runs of ribbon or multiway
  229. cable terminated in a just a TTL input can mangle them.  I suppose
  230. twisted pairs with separate earths and good terminations would be
  231. best, but my own cable is nothing special and I have no problems.
  232. Hopefully you will not either.  However, if the programmer seems to
  233. fail with a verify error at location 0 (the typical indicator of
  234. programmer malfunction), it is worth paying some attention to the
  235. waveforms produced at RB6 and RB7 and the inputs of their associated
  236. buffers.  Ideally you would use an oscilloscope to view them; perhaps
  237. then you can see what might be done to improve them.  Resistive
  238. terminations should be the order of the day, but if you are not proud,
  239. don't own an oscilloscope, and are ready to accept a more empirical
  240. approach: two small caps (10-50pF) one between RB6 and ground and one
  241. between RB7 and ground are certainly worth a try.  This has been
  242. suggested to me a couple of times.  One person mentioned that the
  243. circuit worked with an oscilloscope connected to RB6 and RB7 but
  244. failed to do so when the scope was not connected, so, being a clever
  245. chap he simulated the two scope connections with 1M resistors in
  246. parallel with 12pF and this solved his problem.
  247.   
  248.  
  249. Q8. I have read the programming specs in data sheet DS30189C and your
  250. design cannot possibly work.  If you had read them too you would have
  251. seen that the max current from Vdd (+5V) is rated at 50mA.  Now, let
  252. me point out that the R-on spec for a 4066 switch is 80 Ohms; perhaps
  253. you are not aware of Ohms law, but it says that 0.05*80 = 4V will be
  254. dropped across the switch leaving only 1V for the PIC!  What's more
  255. the maximum possible R-on is much higher than 80 Ohms leaving even
  256. less for the PIC.  What do you have to say to that?
  257.  
  258. A8. Thanks for the electronics lesson.  I can only plead ignorance
  259. (though not of Ohms law!) because I designed the circuit based on the
  260. information in DS30189A which is an earlier version of the data sheet
  261. you quote.  There was no mention of such a high current rating in my
  262. data sheet.  In fact, because my programmer _does_ work, it seems most
  263. unlikely that a typical PIC needs anything like this much current.  I
  264. have measured the voltage drop across the Vdd switch and it is
  265. typically only a few tens of mV (though I must admit I've only tried
  266. this with a few different PICs and 4066s).  I also have connected a
  267. scope to Vdd during programming and I couldn't detect any short
  268. glitches which might indicate large current demands for short amounts
  269. of time.  If you are still worried about this, the 4066 switch can be
  270. ditched in favour of a separate bipolar transistor switch.  Here is an
  271. ASCII sketch of a suitable replacement:
  272.  
  273.                                             +5V
  274.                                              +
  275.                                       ___    |
  276.                                   +--[___]---+
  277.                                   |          |
  278.                    |\      ___    |      B |/ E
  279.            <D2>----| >o---[___]---+--------|     PNP
  280.                    |/                      |\ C
  281.                                              |
  282.                                              +---+ Vdd 
  283.  
  284.  
  285. The resistors can be 10K.  You should retain the 10K//100nF network
  286. connected to Vdd.  Of course it makes sense to change the Vpp switch
  287. too so that you don't need the 4066 at all (the Vpp switch should have
  288. E connected to +13.8V and C connected to Vpp and be driven by the
  289. buffer connected to D3).  If you have already built the hardware and
  290. used a socket for the 4066, a neat idea is to put the transistor
  291. switches on a DIL header and simply replace the 4066 with this.  The
  292. software will need minor changes to account for the inverted operation
  293. of the new switches.  In the programs you'll find definitions for
  294. controlling the LPT pins for both types of buffer.  To get an inverted
  295. signal just borrow the definitions for the opposite type.
  296.  
  297.  
  298. Q9.  Your circuit has an error!  Have you forgotten to include a
  299. pull-up resistor for the O/C buffer driving the ACK pin (pin 10)?
  300.  
  301. A9.  I think you are right.  However, I didn't forget to include one
  302. because I thought that the ACK pin had an internal pull-up.  I don't
  303. use ACK pull-ups on my own programmers and they seem to work.  Anyway,
  304. it can do no harm, and probably some good, if you fit a 10K resistor
  305. between the ACK pin and +5V.  Certainly this is something to try if
  306. you are having trouble getting the programmer to work.
  307.  
  308.  
  309. Q10.  Are there any other designs available, especially for other
  310. members of the PIC family?  If not can your design be suitably
  311. modified?  Where can I get more PIC info?
  312.  
  313. A10.  The 16C84 is particularly well served by DIY programmer designs
  314. and there have been more universal designs published in several hobby
  315. mags (see the PIC FAQ for some pointers).  The 16C5X family cannot be
  316. programmed in serial mode, but I believe most, if not all the 16CXX
  317. PICs could be programmed using some approximation of my hardware.
  318. However, the programming pulses required are considerably different to
  319. those produced by my software; they need to be more accurate for one
  320. thing.  Although it's not an entirely trivial job, it is worth getting
  321. the programming specs and having a go at writing your own programmer
  322. software.  For more info on PICs I only need to give you one
  323. suggestion: get the PIC FAQ.  The FAQ will tell you about the
  324. Microchip BBS and Internet sites, the PICLIST mailing list, the
  325. Parallax Internet site and lots more besides.  To get the PIC FAQ you
  326. can use Andy Errington's Web page:
  327.  
  328.     http://www.lancs.ac.uk/people/cpaame/pic/pic.htm
  329.  
  330. It's links are growing daily and one should point at the latest copy
  331. of the PIC FAQ.  By the way, Andy recommends the everyone interested
  332. in PICs should equip themselves with a copy of Microchip's Embedded
  333. Controller Handbook.
  334.  
  335.  
  336. Q11.  How many programming cycles can I expect to get?
  337.  
  338. A11.  How long is a piece of string?  The expected range of
  339. possibilities is very large.  You should be able to rewrite program
  340. memory an absolute minimum of 100 times and typically a few hundred to
  341. maybe a thousand times.  Data EEPROM can be reprogrammed many hundreds
  342. of thousands of times I think.
  343.  
  344.  
  345. Q12.  Can your hardware be used to read a code-protected 16C84?  Do
  346. you know how to read a code-protected PIC?
  347.  
  348. A12.  I have heard speculation and rumour, nothing more.
  349.  
  350.  
  351. Q13.  Can I use your programmer for in-system programming?
  352.  
  353. A13.  See A4 above for some hints.  Also see Microchip application
  354. note AN589 by Robert Spur for another design.  Although the
  355. application note gives the core routine for serial mode programming,
  356. it needs a wrapper to use it as ready-to-go progamming software.
  357. It's possible to use pp.c or pp.bas instead with just a few mods.
  358.  
  359.  
  360. Q14.  You say in the comments of pp.c that your design is _not_ a
  361. production quality programmer.  What is it then?
  362.  
  363. A14.  It's a prototype programmer.  These are terms used by Microchip.
  364. The difference is based on the thoroughness of the verification
  365. procedures used.  A production programmer not only verifies with Vdd
  366. set at a nominal +5V, but it also does so at other values (typically
  367. +4.5V and +5.5V).  It's no doubt possible to modify my programmer to
  368. do this, but if you are going into production and programming many
  369. PICs you probably owe it to your customers to invest in a more
  370. upmarket programmer.
  371.  
  372.  
  373. Q15.  Thanks for making your programmer design available and I am
  374. very happy with it.  How can I thank you?
  375.  
  376. A15.  Spare a moment to let me know you got it working by sending an
  377. e-mail message to david.tait@man.ac.uk (or to user ID david tait on
  378. the Microchip BBS).  A postcard would be nice if you can't send
  379. e-mail.  Anyway, if it has saved you a bit of time and effort I'll be
  380. happy.
  381.  
  382.  
  383.  
  384. Software Questions
  385. ------------------
  386.  
  387. Q1.  Do I need a QBasic compiler to run the QBasic program?
  388.  
  389. A1.  No.  Just use the interpreter that comes with MS-DOS.  I wrote
  390. the Qbasic stuff so that people without a C compiler could still hack
  391. something.  I'm afraid I learnt QBasic from the on-line help in a
  392. couple of days and it shows.
  393.  
  394.  
  395. Q2.  I built your hardware design using a 7407.  I tried the EXE supplied
  396. and it didn't work.  I tried the Qbasic program and it didn't work either.
  397. What is wrong?
  398.  
  399. A2.  Try a 7406 instead!  The trouble is that both the C and QBasic
  400. programs were set up for hardware employing inverting buffers like the
  401. 7406.  This means the EXE was built for 7406 based hardware too.  The
  402. C program can be reconfigured for non-inverting buffers like the
  403. 7407 by including the line "#define U7407" (it is commented out in the
  404. distributed version).  The Qbasic program can be set up for a 7407 by
  405. using these definitions:
  406.  
  407. CONST DataInv = 0
  408. CONST VppOn = 8, VppOff = 0, VddOn = 4, VddOff = 0
  409. CONST ClkHi = 2, ClkLo = 0, OutHi = 1, OutLo = 0
  410.  
  411. The comments incorrectly suggest that you should use ClkHi = 4.  Surely
  412. very few programs have bugs in the comments!
  413.  
  414.  
  415. Q3.  I monitor the VDD and VPP supplies on my board with LEDs and I see
  416. that one of the supplies is turned on after I reboot my machine.
  417. Is it OK to insert the PIC into the programming socket despite this?
  418.  
  419. A3.  No.  Just run the software with the port number as the only
  420. argument; the program will initialise the port and the supplies will
  421. be switched off.
  422.  
  423.  
  424. Q4.  I am using the C software and I know it is correctly configured
  425. for my hardware but it still doesn't seem to work.  Whenever I try to
  426. program a PIC I get an error message something like this:
  427.  
  428.   pp: 0000: YYYY != XXXX
  429.   pp: Verify failed during programming
  430.  
  431. Nothing I do gets round this.  Can you help?
  432.  
  433. A4.  Reports from people getting this error message account for quite
  434. a bit of the e-mail I receive about my programmer.  Unfortunately on
  435. its own it is not a very helpful diagnostic.  The error simply means
  436. that the programmer tried to program the very first location in
  437. program memory to XXXX (hex) but read back YYYY.  To save programming
  438. cycles the software doesn't try a second time.  (When things are
  439. working properly all locations should program first time anyway.)  The
  440. fact that it was the first location that failed is usually indicative
  441. of some sort of programmer malfunction.  If verify errors occur at
  442. other addresses it's just as likely to be caused by a PIC's EEPROM
  443. becoming unreliable.  I suggest the real answer to your problem will
  444. be found somewhere in the answers to the hardware questions.  However
  445. when you've tried all the ideas from there, you might start to suspect
  446. a timing problem.  In this case it's worth trying the QBasic software
  447. to check your hardware - the QBasic interpreter runs slowly enough for
  448. timing not to be a problem.  If the QBasic stuff works then change the
  449. delay constants (THLD, TSET and TDLY) in the C source.  Compare pp.c
  450. with the source of my PIC reader rp.c to see what changes I have made
  451. for my own 486DX33.  The main idea is to ensure TDLY is about 1
  452. microsecond, and THLD=TSET give the hardware enough time to respond.
  453. In fact the constants I use in rp.c give very long delays, but as they
  454. are still very small compared to the time taken to program a location
  455. (about 10ms) they don't add much to the total time it takes to program the
  456. device - there is really no need to spend time optimising the values.
  457. If you are using my EXE file with a 486 then that may be the problem
  458. in itself.  I suspect the version of Borland C I use has a bug in the
  459. delay() routine (needed to get the 10ms programming delay) that only
  460. manifests itself with some CPU types, though I haven't been able to pin
  461. it down. Try recompiling, maybe the bug is fixed in your compiler.  If
  462. you do recompile you can get stung by another problem: the latest C
  463. compilers will optimise the tiny_delay() routine to nothing.  This
  464. will only be a problem on a fast PC that must rely on this routine to
  465. slow it down.  Again see rp.c for a fix to tiny_delay().  If all else
  466. fails try running the PC at a slower clock speed if you can (some PCs
  467. have a Turbo button for this).
  468.  
  469.  
  470. Q5.  PP.EXE complains that the hardware is not attached when I know
  471. it is.  I have specified the correct port but whatever I do it
  472. refuses to work.  What am I doing wrong?
  473.  
  474. A5. If the hardware is built correctly then nothing.  It's likely you
  475. have a pretty fast PC and/or "slow" hardware.  To check that the
  476. hardware is connected, the program writes to it and reads back the
  477. response immediately; it is possible that the hardware doesn't respond
  478. in time.  See the changes to test_hw() in the source of the PIC reader
  479. rp.c to see how you can cure this.
  480.  
  481.  
  482. Q6.  I hate MS-DOS.  Will your programmer run under Linux?  I hate
  483. MS-DOS boxes.  Will your programmer run on an Amiga/Macintosh/Atari?
  484.  
  485. A6.  The "prog84" package from Wim Lewis will let you use my hardware
  486. under Linux; look for it on ftp://ftp.funet.fi/pub/microprocs/pic (in
  487. the directory burners).  You should also get Ian King's software tools
  488. from the same place (in the directory pictools).  These programs are
  489. probably fairly portable across all PC versions of Unix.  For other
  490. systems, the easiest thing might be for you to write your own
  491. controller in your own favourite language.  My C program will need a
  492. little work for non-MS-DOS machines, but provided you have a C
  493. compiler, a computer with a parallel port, access to I/O routines for
  494. the parallel port and finally a millisecond accuracy delay routine it
  495. shouldn't be too difficult to get it going.  Ironically, having ported
  496. the software from MS-DOS, you might find yourself using an MS-DOS
  497. emulator in order to run a decent assembler/simulator.  I'm told that
  498. using the unmodified C program with an MS-DOS emulator works on the
  499. Amiga.
  500.  
  501.  
  502. Q7.  I notice your program calls a routine named "erase" before it
  503. attempts to program the PIC.  The routine uses the undocumented
  504. commands 1 and 7.  What's going on?
  505.  
  506. A7. This is a routine to disable code protection so that a previously
  507. protected chip can be reprogrammed.  It has the side-effect of bulk
  508. erasing the chip, that is erasing all program and data memory.
  509. Microchip recommend that this procedure is performed before any other
  510. programming is attempted.  However, for some unexplained reason they
  511. don't document the procedure for serial mode.  I just tried the
  512. parallel mode approach and it seems to work.  Someone suggested that
  513. this routine should only be selected if you are programming a
  514. protected PIC thereby decreasing wear and tear on the fuse EEPROM
  515. cells.  They may have a point.  See A11 for other mods of this kind.
  516.  
  517.  
  518. Q8.  How do I produce a suitable file to initialise data EEPROM?
  519.  
  520. A8.  The programmer software takes a word (16-bits) of data from the
  521. hex file and puts the least significant byte into the EEPROM data
  522. memory.  A suitable hex file can be created with any assembler.  I
  523. use MPASM and here's a short example that generates a valid INHX8M
  524. data file:
  525.  
  526.         list p=16c84
  527. ;
  528.         org 0
  529. ;
  530.         data 1,2,3,0xFF
  531.         data 'S,'t,'r,'i,'n,'g,'.
  532.         end
  533.  
  534. Note the special handling of the text string because the software
  535. ignores every second byte of data.
  536.  
  537.  
  538. Q9.  Your programmer seems to work OK with files produced by MPASM
  539. or MPALC.  However I prefer to use the mnemonics offered by the Parallax
  540. assemblers.  Unfortunately your programmer software chokes on Parallax
  541. hex files even though they are INHX8M compatible.  Can you fix that?
  542.  
  543. A9.  The problem (or perhaps advantage) with Parallax files is that
  544. they embed FUSE, ID and EEPROM data into the same file and my software
  545. doesn't expect that.  The best solution is to change the loadhex
  546. function to understand these files.  Alternatively you can simply
  547. ignore the non-program elements of the file by replacing this chunk of
  548. loadhex:
  549.  
  550.       for ( i=0; i<nwords; ++i, ++address ) {
  551.          if ( address >= bufsize )
  552.             quit("Impossible address");
  553.          w = hexword(fp);
  554.          buf[address] = (hextype == INHX8M)? swab(w): w;
  555.       }
  556.  
  557. with
  558.  
  559.       for ( i=0; i<nwords; ++i, ++address ) {
  560.          w = hexword(fp);
  561.          if ( address >= bufsize )
  562.             continue;
  563.          buf[address] = (hextype == INHX8M)? swab(w): w;
  564.       }
  565.  
  566. Of course there is a similar workaround for the QBasic source; look for the
  567. subroutine "LoadHex".  It contains a FOR-NEXT loop that in the
  568. original looks like:
  569.  
  570. FOR i = 1 TO NWords
  571.   IF Address >= BufSize THEN Quit ERRHEX, 0, 0, 0
  572.   wHi = HexByte%(Chan)
  573.   wLo = HexByte%(Chan)
  574.   IF HexType = INHX8M THEN w = 256 * wLo + wHi ELSE w = 256 * wHi + wLo
  575.   IF Which = ProgMem THEN ProgBuf(Address) = w ELSE DataBuf(Address) = w
  576.   Address = Address + 1
  577. NEXT i
  578.  
  579. Delete line 2 and bracket the "IF Which = ....." with another IF
  580. statement to get this:
  581.  
  582. FOR i = 1 TO NWords
  583.   wHi = HexByte%(Chan)
  584.   wLo = HexByte%(Chan)
  585.   IF HexType = INHX8M THEN w = 256 * wLo + wHi ELSE w = 256 * wHi + wLo
  586.   IF Address < BufSize THEN
  587.     IF Which = ProgMem THEN ProgBuf(Address) = w ELSE DataBuf(Address) = w
  588.   ENDIF
  589.   Address = Address + 1
  590. NEXT i
  591.  
  592.  
  593. Q10.  I have version 0.3 of your software.  Do you have you an updated
  594. version?
  595.  
  596. A10.  No.  The existing version works for me and does everything I
  597. need, so I doubt if I'll ever get round to producing a significantly
  598. better version.  An important function that you might want is a
  599. routine to read the PIC and so I have written a separate utility to do
  600. that; it is also easy enough to verify a PIC by combining the PIC
  601. reader functionality with the loadhex routine from the programmer
  602. source.  The core parts of rp.c and rp.bas are tiny routines to
  603. actually read the PIC and some routines to spit out INHX8M files;
  604. the rest is much the same as pp.c and pp.bas.  If you _really_
  605. wanted INHX16, check loadhex() for hints on the difference.
  606.  
  607.  
  608. Q11.  The time to program the PIC seems independent of the number of
  609. locations that must be programmed.  Why?
  610.  
  611. A11.  My software programs all locations every time.  It is easy to
  612. change this behaviour.  One modification you might consider would be
  613. to read the entire PIC (program/data/fuses) into a buffer and then
  614. only reprogram the items that differ from the new values.  The
  615. verify() and config() routines can be modified and combined to read
  616. the entire PIC.
  617.  
  618.  
  619. Q12.  I use the QBasic program and sometimes when I quit I get a blank
  620. screen and the machine seems dead.  Can I fix that?
  621.  
  622. A12.  Yes.  If you type CLS the screen will come back to life.  Fix
  623. the source by adding a CLS statement just before each occurrence of
  624. the END statement (a couple of places).  You can also replace END
  625. with SYSTEM for a more abrupt end.
  626.  
  627.  
  628. Q13.  I use MPASM which amongst other things produces .obj files.  The
  629. instructions for pp.c say it expects "objfiles" but when I try to use
  630. the .obj files it complains.  Why?
  631.  
  632. A13.  You should use the .hex files produced by MPASM.  I know my name
  633. is confusing, but it's because when I wrote the program I used the MPALC
  634. naming convention.  MPASM produces INHX8M by default whereas MPALC
  635. produced INHX16, so you might like to change the programmer defaults
  636. if you use MPASM (or the Parallax assembler with the A9 fix).
  637.  
  638.  
  639. Q14.  My PC makes a noise when I run your QBasic program.  Is anything
  640. wrong?
  641.  
  642. A14.  No.  I use the Qbasic PLAY command to get a small delay and on
  643. some PCs this can lead to a slight purr from the internal speaker.  If
  644. you find it objectionable just replace the "PrgDly" routine with a
  645. FOR-NEXT loop that wastes an amount of time of at least 10ms.
  646.  
  647.  
  648. Q15.  Can I use your software from a DOS window under Windows?
  649.  
  650. A15.  Try it.  On my own PC the C version runs OK, but the QBasic
  651. program seems to have problems; perhaps the way I time the programming
  652. signals is being interfered with by Windows somehow.
  653.  
  654.  
  655. Q16.  Is that all?
  656.  
  657. A16.  I hope so.
  658.